package org.ruiyichen.guizhou.agr.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.ruiyichen.guizhou.agr.R;
import org.ruiyichen.guizhou.agr.bean.mode.AgileDeviceModel;
import org.ruiyichen.guizhou.agr.imp.IIrrigatedDeviceFilter;
import org.ruiyichen.guizhou.agr.ui.listener.OnRecyclerItemClick;
import org.ruiyichen.guizhou.agr.utils.StrUtil;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;


/**
 * 类描述：家庭成员
 *
 * @version 1.0
 */
public class AgileDeviceHistoryRecyclerAdapter extends RecyclerView.Adapter<AgileDeviceHistoryRecyclerAdapter.BViewHolder> {

    private List<AgileDeviceModel> mDatas;
    private Context mContext;
    private LayoutInflater inflater;

    private OnRecyclerItemClick onRecyclerItemClick;


    public AgileDeviceHistoryRecyclerAdapter(Context context) {
        this.mContext = context;
        inflater = LayoutInflater.from(mContext);
    }

    public void setmDatas(List<AgileDeviceModel> mDatas) {
        this.mDatas = mDatas;
        notifyDataSetChanged();
    }

    public void setOnRecyclerItemClick(OnRecyclerItemClick onRecyclerItemClick) {
        this.onRecyclerItemClick = onRecyclerItemClick;
    }

    //填充onCreateViewHolder方法返回的holder中的控件
    @Override
    public void onBindViewHolder(BViewHolder holder, final int position) {
        AgileDeviceModel model = mDatas.get(position);
        if (model != null) {
            holder.tv_agile_detail_device.setText("采集设备名称：" + model.deviceName);
            holder.tv_agile_detail_time.setText("完成时间：" + model.stopTime);
            holder.tv_agile_detail_setting_pressure.setText("设定压力：" + model.settingPressure);
            holder.tv_agile_detail_real_pressure.setText("时间压力：" + model.pressure);
            holder.tv_agile_detail_recipe.setText("规格：" + model.recipe);
            holder.tv_agile_detail_tension_value.setText("伸长量：" + model.tensionValue);
            holder.tv_agile_detail_group_id.setText("班组号：" + model.groupId);
            holder.tv_agile_detail_model_number.setText("模具号：" + model.modleNumber);
            holder.tv_agile_detail_total.setText("总计：" + model.total);
            holder.tv_agile_detail_sub_total.setText("小计：" + model.subtotal);
            if (StrUtil.isNotEmpty(model.message)) {
                holder.tv_agile_detail_message.setVisibility(View.VISIBLE);
                holder.tv_agile_detail_message.setText("!报警信息：" + model.message);
            } else {
                holder.tv_agile_detail_message.setVisibility(View.GONE);
            }
        }
    }

    //重写onCreateViewHolder方法，返回一个自定义的ViewHolder
    @Override
    public BViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.df_item_agile_device_history, parent, false);
        BViewHolder holder = new BViewHolder(view);
        return holder;
    }

    @Override
    public int getItemCount() {
        if (mDatas == null) return 0;
        return mDatas.size();
    }


    /**
     * 协办员
     */
    class BViewHolder extends RecyclerView.ViewHolder {

        TextView
                tv_agile_detail_device,
                tv_agile_detail_time,
                tv_agile_detail_setting_pressure,
                tv_agile_detail_real_pressure,
                tv_agile_detail_recipe,
                tv_agile_detail_tension_value,
                tv_agile_detail_group_id,
                tv_agile_detail_model_number,
                tv_agile_detail_total,
                tv_agile_detail_sub_total,
                tv_agile_detail_message;

        public BViewHolder(final View view) {
            super(view);

            tv_agile_detail_device = view.findViewById(R.id.tv_agile_detail_device);
            tv_agile_detail_time = view.findViewById(R.id.tv_agile_detail_time);
            tv_agile_detail_setting_pressure = view.findViewById(R.id.tv_agile_detail_setting_pressure);
            tv_agile_detail_real_pressure = view.findViewById(R.id.tv_agile_detail_real_pressure);
            tv_agile_detail_recipe = view.findViewById(R.id.tv_agile_detail_recipe);
            tv_agile_detail_tension_value = view.findViewById(R.id.tv_agile_detail_tension_value);
            tv_agile_detail_group_id = view.findViewById(R.id.tv_agile_detail_group_id);
            tv_agile_detail_model_number = view.findViewById(R.id.tv_agile_detail_model_number);
            tv_agile_detail_total = view.findViewById(R.id.tv_agile_detail_total);
            tv_agile_detail_sub_total = view.findViewById(R.id.tv_agile_detail_sub_total);
            tv_agile_detail_message = view.findViewById(R.id.tv_agile_detail_message);
        }
    }
}
